const Controller = require('egg').Controller;

class LabelController extends Controller {
    // 编辑文章标签
	async label_edit() {
		let query = this.ctx.request.body,
			params = {
                name: query.name
            };
		try {
            const label = await this.ctx.service.label.label_edit(params);
            this.ctx.status = 200;
            return this.ctx.body = {
                s: 1,
                m: 'ok~',
                d: label
            };
		}catch(err) {
			return this.ctx.body = {
				s: 0,
				m: `Fail~${err}`
			}
		}
    }
    /**
     * 文章标签列表
     * @permission 'label:v0.0.1:list'
     */
    async label_list() {
        const auth = this.ctx.session.user;
        try{
            const LABEL_LIST = await this.ctx.service.label.label_list();
            this.ctx.status = 200;
            return this.ctx.body = {
                s: 1,
                m: 'ok',
                d: LABEL_LIST,
            }
        } catch(err) {
            return this.ctx.body = {
                s: 0,
                m: `fail~${err}`
            }
        }

    }
    // 删除文章标签
    async label_del() {
        const query = this.ctx.request.body,
            id = query.id;
        try {
            const LABEL_DEL = await this.ctx.service.label.label_del({id});
            console.log('47......',LABEL_DEL);
            this.ctx.status = 200;
            return this.ctx.body = {
                s: 1,
                m: `ok~`,
                d: {}
            };
        } catch(err) {
            return this.ctx.body = {
                s: 0,
                m: `fail~${err}`
            }
        }
    }
}

module.exports = LabelController;